# -*- coding: utf-8 -*-
# @Time    : 18-2-8 下午4:09
# @Author  : huanggz
# @Email   : 308602626@qq.com
# @File    : mysql_change_type.py
# @Software: PyCharm
from mysql_conf import mysel_conf
conn = mysel_conf.pool()
cursor = conn.cursor()
sql_media_type='SELECT  id FROM qdbuluo.contents where media_type=2 '
cursor.execute(sql_media_type)
res_media_type= cursor.fetchall()

for i in  res_media_type:
    sql_ext = f'SELECT count(*) as num FROM qdbuluo.contents_ext where contents_id={ i["id"]} '
    cursor.execute(sql_ext)
    res_sql_ext = cursor.fetchone()

    if not res_sql_ext['num']:
        update_sql=f'UPDATE  qdbuluo.contents  SET media_type=4 WHERE id={i["id"]}'
        cursor.execute(update_sql)
        conn.commit()